package dao;

import org.apache.ibatis.annotations.*;
import pojo.Doctor;

import java.util.List;

public interface DoctorMapper {

    @Select("SELECT * FROM doctor")
    @Results({
            @Result(column = "doc_id", property = "doc_id"),
            @Result(column = "doc_name", property = "doc_name"),
            @Result(column = "sex", property = "sex"),
            @Result(column = "nation", property = "nation"),
            @Result(column = "work_year", property = "work_year"),
            @Result(column = "politicstatus", property = "politicstatus"),
            @Result(column = "doc_title", property = "doc_title"),
            @Result(column = "education", property = "education"),
            @Result(column = "introduction", property = "introduction"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "depart_id1", property = "depart_id1"),
            @Result(column = "depart_id2", property = "depart_id2"),
            @Result(column = "birthdate", property = "birthdate"),
            @Result(column = "user_name", property = "user_name"),
            @Result(column = "img", property = "img"),
            @Result(column = "recommend", property = "recommend")
    })
    List<Doctor> findAll();

    @Select("SELECT * FROM doctor WHERE doc_id = #{docId}")
    @Results({
            @Result(column = "doc_id", property = "doc_id"),
            @Result(column = "doc_name", property = "doc_name"),
            @Result(column = "sex", property = "sex"),
            @Result(column = "nation", property = "nation"),
            @Result(column = "work_year", property = "work_year"),
            @Result(column = "politicstatus", property = "politicstatus"),
            @Result(column = "doc_title", property = "doc_title"),
            @Result(column = "education", property = "education"),
            @Result(column = "introduction", property = "introduction"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "depart_id1", property = "depart_id1"),
            @Result(column = "depart_id2", property = "depart_id2"),
            @Result(column = "birthdate", property = "birthdate"),
            @Result(column = "user_name", property = "user_name"),
            @Result(column = "img", property = "img"),
            @Result(column = "recommend", property = "recommend")
    })
    Doctor findById(String docId);

@Select("SELECT * FROM doctor WHERE depart_id1 = #{depart_id1}")
    @Results({
            @Result(column = "doc_id", property = "doc_id"),
            @Result(column = "doc_name", property = "doc_name"),
            @Result(column = "sex", property = "sex"),
            @Result(column = "nation", property = "nation"),
            @Result(column = "work_year", property = "work_year"),
            @Result(column = "politicstatus", property = "politicstatus"),
            @Result(column = "doc_title", property = "doc_title"),
            @Result(column = "education", property = "education"),
            @Result(column = "introduction", property = "introduction"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "depart_id1", property = "depart_id1"),
            @Result(column = "depart_id2", property = "depart_id2"),
            @Result(column = "birthdate", property = "birthdate"),
            @Result(column = "user_name", property = "user_name"),
            @Result(column = "img", property = "img"),
            @Result(column = "recommend", property = "recommend")
    })
    List<Doctor> findByDepartId1(String depart_id1);


    @Insert("INSERT INTO doctor (doc_id, doc_name, sex, nation, work_year, politicstatus, " +
            "doc_title, education, introduction, telephone, depart_id1, depart_id2, " +
            "birthdate, user_name, img, recommend) " +
            "VALUES (#{doc_id}, #{doc_name}, #{sex}, #{nation}, #{work_year}, #{politicstatus}, " +
            "#{doc_title}, #{education}, #{introduction}, #{telephone}, #{depart_id1}, #{depart_id2}, " +
            "#{birthdate}, #{user_name}, #{img}, #{recommend})")
    int add(Doctor doctor);

    @Update("UPDATE doctor SET doc_name = #{doc_name}, sex = #{sex}, nation = #{nation}, " +
            "work_year = #{work_year}, politicstatus = #{politicstatus}, " +
            "doc_title = #{doc_title}, education = #{education}, introduction = #{introduction}, " +
            "telephone = #{telephone}, depart_id1 = #{depart_id1}, depart_id2 = #{depart_id2}, " +
            "birthdate = #{birthdate}, user_name = #{user_name}, img = #{img}, recommend = #{recommend} " +
            "WHERE doc_id = #{doc_id}")
    int update(Doctor doctor);

    @Delete("DELETE FROM doctor WHERE doc_id = #{docId}")
    int delete(String docId);

    // 新增或修改为按 doc_name 查询
    @Select("SELECT * FROM doctor WHERE doc_name LIKE CONCAT('%', #{doc_name}, '%')")
    List<Doctor> findByDocName(String doc_name);

    @Select("SELECT * FROM doctor WHERE user_name = #{user_name}")
    @Results({
            @Result(column = "doc_id", property = "doc_id"),
            @Result(column = "doc_name", property = "doc_name"),
            @Result(column = "sex", property = "sex"),
            @Result(column = "nation", property = "nation"),
            @Result(column = "work_year", property = "work_year"),
            @Result(column = "politicstatus", property = "politicstatus"),
            @Result(column = "doc_title", property = "doc_title"),
            @Result(column = "education", property = "education"),
            @Result(column = "introduction", property = "introduction"),
            @Result(column = "telephone", property = "telephone"),
            @Result(column = "depart_id1", property = "depart_id1"),
            @Result(column = "depart_id2", property = "depart_id2"),
            @Result(column = "birthdate", property = "birthdate"),
            @Result(column = "user_name", property = "user_name"),
            @Result(column = "img", property = "img"),
            @Result(column = "recommend", property = "recommend")
    })
    List<Doctor> findByUserName(String user_name);
}